/*
    实现MyThread中定义的继承接口的类
*/
#include "MyThread.h"

FunctionThread::FunctionThread(FunctionInterface* pFunctionInterface):FunctionThreadInterface(pFunctionInterface) {
}

FunctionThread::~FunctionThread() {
}

// 封装相应功能函数到线程执行体
void* FunctionThread::StartFunctionOfThread(void *pThis){

    FunctionThread* pThreadThis=(FunctionThread *)pThis;
    printf("当前线程ID：%ld\n", pThreadThis->threadID);
    pThreadThis->pThreadFunctionInterface->RunFunction(); // 转到对应的功能函数
    return 0;
}

// 启动线程
void FunctionThread::Run(){
    int res = pthread_create(&threadID, 0, StartFunctionOfThread, this); // 在这里创建的线程

    if(res != 0){
        printf("pthread_create error\n");
        return ;
    }
}

// 等待线程结束
void FunctionThread::WaitForDeath(){
    int res = pthread_join(threadID, 0);
    if(res != 0){
        printf("In FunctionThread::WaitForDeath(),pthread_join error\n");
        return ;
    }
}




